package com.example.demo.log;

import com.example.demo.signature.PublicUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class DGuanCommonParam {

    //应用账号
    private String appId;
    //应用秘钥
    private String appSecret;
    //时间戳（ms），有效期5分钟
    private Long timestamp;
    //接口票据
    private String token;

    public DGuanCommonParam(String appId, String appSecret, Long timestamp) {
        this.appId = appId;
        this.appSecret = appSecret;
        this.timestamp = timestamp;
    }

    public String getTokenSign() {
        if (PublicUtils.isEmptyString(appId) || PublicUtils.isEmptyString(appSecret) || timestamp == null) {
//            throw new CheckedException(Result.PARAM_ERROR, "缺少参数");
        }
        String sign = appId + appSecret + "$" + timestamp;
        return sign;
    }

    public String getSign() {
        if (PublicUtils.isEmptyString(token) || PublicUtils.isEmptyString(appId)
                || PublicUtils.isEmptyString(appSecret) || timestamp == null) {
//            throw new CheckedException(Result.PARAM_ERROR, "缺少参数");
        }
        String sign = token + appId + appSecret + "$" + timestamp;
        return sign;
    }
}
